#include "pch.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

class Solution {
public:
	int maxProduct(vector<int>& nums) {
		int len = nums.size();
		if (len == 0) return 0;

		vector<int> fmax(len);
		vector<int> fmin(len);
		fmax[0] = nums[0];
		fmin[0] = nums[0];

		for (int i = 1;i < len;i++)
		{
			fmin[i] = min(fmin[i - 1] * nums[i], min(nums[i], fmax[i - 1] * nums[i]));
			fmax[i] = max(nums[i] * fmax[i - 1],max(nums[i] * fmin[i - 1], nums[i]));
		}
		cout << "min" << endl;
		for (int num : fmin)
		{
			cout << "* " << num << endl;
		}
		cout << "max" << endl;
		for (int num : fmax)
		{
			cout <<"* "<< num << endl;
		}

		return *max_element(fmax.begin(),fmax.end());
	}
};
int main()
{	
	vector<int> v{ 1,2,-1,-2,2,1,-2,1,4,-5,4 };
	Solution s;
	int res = s.maxProduct(v);
	cout << res << endl;
	return 0;
}